package common.controls
{
	import common.controls.utils.FilterUtils;
	
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	
	/**  
	 * 显示对象
	 * @author carrey
	 * */ 
	public class AKSprite  extends Sprite
	{
		protected var _selected:Boolean = false;
		protected var _overSelected:Boolean = false;
		
		private var _isAutoSize:Boolean = true;
		protected var _index:int = 0;
		
		protected var _enabled:Boolean = true;
		
		protected var _width:int;
		protected var _height:int;
		protected var _baseBack:Shape;
		protected var _container:Sprite;
		
		public function AKSprite()
		{
			init();
		}
		
		private function init():void
		{
			_baseBack = new Shape();
			_baseBack.graphics.clear();
			_baseBack.graphics.beginFill(0,0);
			_baseBack.graphics.drawRect(0, 0, 1, 1);
			_baseBack.graphics.endFill();
			addChild( _baseBack );
			
			_container = new Sprite();
			addChild( _container );
		}
		
		public function autoSize():void
		{
			_isAutoSize = true;
		}
		
		public function setSize( w:int, h:int ):void
		{
			_isAutoSize = false;
			
			_width = w;
			_height = h;
			
			_baseBack.width = w;
			_baseBack.height = h;
		}
		
		public function setLocation( x:int, y:int ):void
		{
			this.x = x;
			this.y = y;
		}
		
		override public function get width():Number
		{
			if( _isAutoSize )
			{
				return super.width;
			}
			return _width;
		}
		
		override public function get height():Number
		{
			if( _isAutoSize )
			{
				return super.height;
			}
			return _height;
		}
		
		public function set index( value:int ):void
		{
			_index = value;
		}
		
		public function get index():int
		{
			return _index;
		}
		
		public function set enabled( value:Boolean ):void
		{
			_enabled = value;
			if( _enabled )
			{
				this.filters = null;
			}
			else
			{
				this.filters = FilterUtils.getGrayFilter();
			}
		}
		
		public function get enabled():Boolean
		{
			return _enabled
		}
		
		public function set selected( value:Boolean ):void
		{
			_selected = value;
		}
		
		public function get selected():Boolean
		{
			return _selected;
		}
		
		public function set overSelected( value:Boolean ):void
		{
			_overSelected = value;
		}
		
		public function get overSelected():Boolean
		{
			return _overSelected;
		}
		
		protected function addChildIn( child:DisplayObject ):DisplayObject
		{
			return _container.addChild( child );
		}
		
		protected function addChildInAt( child:DisplayObject, index:int ):DisplayObject
		{
			return _container.addChildAt( child, index );
		}
	}
}

